package com.xfzp.android.ms;

import android.opengl.Matrix;

import com.xfzp.d3.Axis;
import com.xfzp.d3.Cube;

/**
 * 
 * @author AndroidApe
 * @version 2011-11-14
 */
public class Layer {
	public final byte axis;// 可选值为Axis.X、Axis.Y、Axis.Z
	private int[] cubeIndex;
	private Cube[] cube;

	public Layer(byte axis, int[] cubeIndex) {
		this.axis = axis;
		this.cubeIndex = cubeIndex;
		cube = new Cube[cubeIndex.length];
	}

	/**
	 * 旋转
	 * 
	 * @param angle
	 */
	public void rotate(float angle) {
		float x1, y1, z1;
		x1 = y1 = z1 = 0;
		if (axis == Axis.X)
			x1 = 1;
		else if (axis == Axis.Y)
			y1 = 1;
		else if (axis == Axis.Z)
			z1 = 1;
		float[] m = new float[16];
		Matrix.setIdentityM(m, 0);
		Matrix.rotateM(m, 0, angle, x1, y1, z1);
		for (Cube c : cube) {
			if (c != null) {
				c.multiply(m);
			}
		}
	}

	public int[] getCubeIndex() {
		return cubeIndex;
	}

	public void setCube(int index, Cube cube) {
		this.cube[index] = cube;
	}
}
